package com.ego.item.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ego.item.pojo.Stock;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 〈〉
 *
 * @author coach tam
 * @email 327395128@qq.com
 * @create 2020/11/25
 * @since 1.0.0
 * 〈坚持灵活 灵活坚持〉
 */
public interface StockMapper extends BaseMapper<Stock> {

    @Select("select count(sku_id) from tb_stock where sku_id = #{skuId} for update")
    int lockStock(@Param("skuId") Long skuId);

    @Update("update tb_stock set stock = stock - #{num} where sku_id = #{skuId} and stock >= #{num} ")
    int reduceStock(@Param("skuId") Long skuId, @Param("num") Integer num);
}
